//
//  NewScrollView.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/4/21.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "NewScrollView.h"
#import "InterFace.h"
#import "RoundBut.h"
#import "UIButton+WebCache.h"
#import "ProductModel.h"
#import "CategoryModel.h"


@implementation NewScrollView

- (instancetype)initWithRoundButTitle:(NSArray *)titleArr frame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //        for (int i = 0; i < [titleArr count]; i++) {
        for (int i = 0; i < 3; i++) {
            
            RoundBut *roundBut = [[RoundBut alloc]initWithFrame:CGRectMake(i * self.frame.size.width / 3 + 15 , 20, (SCREEN_WIDTH-160)/3.0, 80)];
            [roundBut addTarget:self action:@selector(roundButClick:) forControlEvents:UIControlEventTouchUpInside];
            roundBut.titleLabel.font = [UIFont systemFontOfSize:13.0];
            CategoryModel *model = [titleArr firstObject];
            roundBut.tag = i+1;
            
            if (i== 0) {
                [roundBut setTitle:model.CategoryName forState:UIControlStateNormal];
                
                [roundBut sd_setImageWithURL:[NSURL URLWithString:model.IconPath] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                    roundBut.imageView.layer.cornerRadius = roundBut.imageView.frame.size.width / 2;
                }];
                
                
            } else if(i==1){
                RoundBut *button = [[RoundBut alloc]initWithFrame:CGRectMake(i * self.frame.size.width / 3 + 15 , 20, (SCREEN_WIDTH-90)/3.0, (SCREEN_WIDTH-45)/3.0)];
                [button addTarget:self action:@selector(roundButClick:) forControlEvents:UIControlEventTouchUpInside];
                button.titleLabel.font = [UIFont systemFontOfSize:13.0];
                [button setBackgroundImage:[UIImage imageNamed:@"首页--3_07(1)"] forState:UIControlStateNormal];
                button.tag = i+1;
                [self addSubview:button];
                [roundBut setTitle:@"优惠价格" forState:UIControlStateNormal];
                
            } else if(i==2){
                RoundBut *button = [[RoundBut alloc]initWithFrame:CGRectMake(i * self.frame.size.width / 3 + 15 , 20, (SCREEN_WIDTH-90)/3.0, (SCREEN_WIDTH-45)/3.0)];
                [button addTarget:self action:@selector(roundButClick:) forControlEvents:UIControlEventTouchUpInside];
                button.titleLabel.font = [UIFont systemFontOfSize:13.0];
                [button setBackgroundImage:[UIImage imageNamed:@"首页--3_05(1)"] forState:UIControlStateNormal];
                button.tag = i+1;
                [self addSubview:button];
                ////                  [roundBut setImage:[UIImage imageNamed:@"首页--3_07(1)"] forState:UIControlStateNormal];
                //                [roundBut setBackgroundImage:[UIImage imageNamed:@"首页--3_07(1)"] forState:UIControlStateNormal];
                //                roundBut.imageView.frame = CGRectMake(0, 0, self.frame.size.height - 5, 0);
                [roundBut setTitle:@"账户" forState:UIControlStateNormal];
            }
            
            
            [self addSubview:roundBut];
        }
    }
    return self;
}

+ (instancetype)newScrollViewRoundButTitle:(NSArray *)titleArr frame:(CGRect)frame{
 
    NewScrollView *scrollew = [[NewScrollView alloc] initWithRoundButTitle:titleArr frame:frame];
    return scrollew;
}

#pragma -mark RoundBut点击事件

- (void)roundButClick:(RoundBut *)sender{

  
    [self.mydelegate getBut:sender];
    
}




@end
